package com.lai.qq.route.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lai.qq.route.gateway.service.GatewayService;

/**
 * @author: ou.xiangrui
 * @date : 2020/4/22
 */
@RestController
@RequestMapping("/gateway")
public class GatewayController {
    @Autowired
    private GatewayService gatewayService;

    /**
     * 同步网关配置，类似于Zuul网关的/actuator/refresh，遍历数据库中记录
     * 
     * @return
     */
    @RequestMapping("/loadRoute")
    public String loadRoute() {
        return gatewayService.loadRoute();
    }

    /**
     * 刷新数据库添加的路由
     * 
     * @param routeId
     * @return
     */
    @RequestMapping("/addRoute")
    public String addRoute(String routeId) {
        return gatewayService.addRoute(routeId);
    }

    /**
     * 刷新数据库中更新的路由
     * 
     * @param routeId
     * @return
     */
    @RequestMapping("/upateRoute")
    public String upateRoute(String routeId) {
        return gatewayService.upateRoute(routeId);
    }

    /**
     * 先删除路由，再删除数据库中数据
     * 
     * @param routeId
     * @return
     */
    @RequestMapping("/deleteRoute")
    public String deleteRoute(String routeId) {
        return gatewayService.deleteRoute(routeId);
    }
}
